package org.reborn.engine.input.jinput

import org.reborn.engine.input._
import org.reborn.utils.PropertyUtil
import net.java.games.input.{Mouse => JIMouse, Keyboard => JIKeyboard, Component}

trait JIComponent[T]{
  self: DeviceComponent[T] =>
  val jiComponent:Option[Component]
  protected var state = pollDataToState(0.0f)
  
  protected def pollDataToState(pollData:Float):T
  
  def updateComponentState(){
	for(comp <- jiComponent){
	  update(pollDataToState(comp.getPollData))
	}
  }
}

trait JIBooleanComponent{ protected def pollDataToState(pollData:Float):Boolean = {pollData != 0.0f} }

trait JIFloatComponent{ protected def pollDataToState(pollData:Float):Float = {pollData} }

abstract class JIComponentSupport[T](val componentName:String, component:Component)
	extends DeviceComponent[T] with JIComponent[T]{
  val jiComponent = Option(component)
}

class JIButton(componentName:String, component:Component)
	extends JIComponentSupport[Boolean](componentName:String, component:Component) 
	with ButtonComponent with JIComponent[Boolean] with JIBooleanComponent
	
class JIAnalogButton(componentName:String, component:Component)
	extends JIComponentSupport[Float](componentName:String, component:Component)
	with AnalogButtonComponent with JIComponent[Float] with JIFloatComponent
	
class JIPositionChange(componentName:String, component:Component)
	extends JIComponentSupport[Float](componentName:String, component:Component)
	with PositionChangeComponent with JIComponent[Float] with JIFloatComponent
